using System;
using System.Collections.Generic;
using System.Resources;

namespace needle.Services.astra.Collections
{
	/// <summary>
	/// <see cref="NamedValueKey{T}"/> with <see cref="NamedValueKey{T}.Name"/> loaded from assembly resources.
	/// </summary>
	/// <typeparam name="T"><see cref="ValueKey{T}.Id"/> type.</typeparam>
	public abstract class ResourceNamedValueKey<T> : NamedValueKey<T>
	{
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <remarks>Calls <see cref="Validate"/>(<paramref name="id"/>).</remarks>
		/// <param name="id">See <see cref="Id"/>.</param>
		public ResourceNamedValueKey(T id)
			: base(id)
		{
		}

		/// <summary>
		/// See <see cref="NamedValueKey{T}.Name"/>.
		/// </summary>
		/// <value>
		/// Gets name from <see cref="ResourceManager"/>.<see cref="ResourceManager.GetString(string)"/>(<see cref="ResourceName"/>).
		/// </value>
		public override string Name
		{
			get { return this.ResourceManager.GetString(this.ResourceName); }
		}

		/// <summary>
		/// Resource manager for getting names.
		/// </summary>
		protected abstract ResourceManager ResourceManager
		{
			get;
		}
		/// <summary>
		/// Resource name prefix used by <see cref="ResourceName"/>.
		/// </summary>
		/// <value>"ValueKey_".</value>
		protected virtual string ResourceNamePrefix
		{
			get { return "ValueKey_"; }
		}
		/// <summary>
		/// Resource name for <see cref="Name"/>.
		/// </summary>
		/// <value><see cref="ResourceNamePrefix"/> + <see cref="Id"/>.<see cref="ToString"/>.</value>
		protected virtual string ResourceName
		{
			get { return this.ResourceNamePrefix + this.Id.ToString(); }
		}
	}
}
